#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<unordered_map>

using namespace std;

vector<vector<string>> groupAnagrams(vector<string>& strs) {
    unordered_map<string, vector<string>> m;
    for (auto s : strs)
    {
        string t = s;
        sort(t.begin(), t.end());
        m[t].push_back(s);
    }

    vector<vector<string>> ans;
    for (auto it : m)
        ans.push_back(it.second);

    return ans;
}

int main()
{
    vector<string> str = { "eat", "tea", "tan", "ate", "nat", "bat" };
    groupAnagrams(str);
    return 0;
}